﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YArchitech.Revit
{
	public static class RevitViewExtension
	{
		public static void HideYJKElements(this View view, ElementSet elemSet)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			foreach (object obj in elemSet)
			{
				Element element = (Element)obj;
				collection.Add(element.Id);
			}
			view.HideElements(collection);
		}

		public static void UnHideYJKElements(this View view, ElementSet elemSet)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			foreach (object obj in elemSet)
			{
				Element element = (Element)obj;
				collection.Add(element.Id);
			}
			view.UnhideElements(collection);
		}

		public static ViewDrafting CreateViewDrafting(Document doc)
		{
			ViewDrafting result = null;
			ViewFamilyType viewFamilyType = null;
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).ToElements())
			{
				ViewFamilyType viewFamilyType2 = element as Autodesk.Revit.DB.ViewFamilyType;
				if (viewFamilyType2.ViewFamily == 108)
				{
					viewFamilyType = viewFamilyType2;
				}
			}
			if (viewFamilyType != null)
			{
				result = ViewDrafting.Create(doc, viewFamilyType.Id);
			}
			return result;
		}

		public static string GetViewTitle(View view)
		{
			return view.Title;
		}

		public static void GetRevitWndRectangle(UIView view, ref int left, ref int top, ref int right, ref int bottom)
		{
			Rectangle windowRectangle = view.GetWindowRectangle();
			left = windowRectangle.Left;
			top = windowRectangle.Top;
			right = windowRectangle.Right;
			bottom = windowRectangle.Bottom;
		}
	}
}
